<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>管理系统</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  {:widget_st('layui','css')}
</head>
{:do_action('admin_head')}
<body>

  
  <div class="layui-form" lay-filter="layuiadmin-form-role" id="layuiadmin-form-role" style="padding: 20px 30px 0 0;">
    <form  class="info_tj" onclick="return false;">
      <input type="hidden" name="id" value="{$res['id']}">
      <div class="layui-form-item">
        <label class="layui-form-label">分类名</label>
        <div class="layui-input-inline">
          <input type="text" name="name"  autocomplete="off" class="layui-input" value="{$res['name']}" readonly>
        </div>
      </div>
 
      <div class="layui-form-item">
        <label class="layui-form-label">权限范围</label>
        <div class="layui-input-block">
          <input type="checkbox" lay-skin="primary"  id="c_all" lay-filter="c_all" title="全部">
          <input type="checkbox" lay-skin="primary"  id="f_all" lay-filter="f_all" title="反选"><br>
          <?php foreach($list as $k=>$vo){ ?>
            <input type="checkbox" name="role[]" value="{$vo['id']}" lay-skin="primary"  class="zf_role" title="<?php echo '┃'.str_repeat('━━', substr_count($vo['value'],'  '));?> {$vo['name']}({$vo['control']}/{$vo['act']})" <?php echo in_array($vo['id'],$role_list)?'checked':''; ?> ><br>
          <?php  } ?>



        </div>
      </div>
      <div class="layui-form-item">
        <div class="layui-input-block">
          <button class="layui-btn tijiao" type="submit" lay-submit lay-filter="LAY-auth-tree-submit">提交</button>
        </div>
      </div>
    </form>
  </div>

  {:widget_st('layui','js')}  
  {:widget_st('jq','js')}

<script>
layui.use(['jquery', 'form', 'layer'], function(){
    var $ = layui.$
    ,form = layui.form ;

    form.on('checkbox(c_all)', function (data) {
      var a = data.elem.checked;
      if (a == true) {
        $(".zf_role").prop("checked", true);
        form.render('checkbox');
      } else {
        $(".zf_role").prop("checked", false);
        form.render('checkbox');
      }

    });
    //反选
    form.on('checkbox(f_all)', function (data) {
      var item = $(".zf_role");
      item.each(function () {
        if ($(this).prop("checked")) {
          $(this).prop("checked", false);
        } else {
          $(this).prop("checked", true);
        }
      })
      form.render('checkbox');


    });
    //有一个未选中全选取消选中
    form.on('checkbox(c_one)', function (data) {
      var item = $(".zf_role");
      for (var i = 0; i < item.length; i++) {
        if (item[i].checked == false) {
          $("#c_all").prop("checked", false);
          form.render('checkbox');
          break;
        }
      }
      //如果都勾选了  勾上全选
      var  all=item.length;
      for (var i = 0; i < item.length; i++) {
        if (item[i].checked == true) {
          all--;
        }
      }
      if(all==0){
        $("#c_all").prop("checked", true);
        form.render('checkbox');}
    });



    $(".tijiao").on("click",function(){
      var data = $(".info_tj input,.info_tj textarea").serialize();      
      $.ajax({
          type:'post',
          url:"{:url('admin/config/admin_group_role')}",
          data:data,
          dataType:'json',
          success:function(res){
            // console.log(res)
            if(res.result==1){
              layer.msg("修改成功", {icon: 1});
              setTimeout(function() {
                window.parent.location.reload();
              }, 2000);
            }else{
              layer.msg(res.msg, {icon: 2});
              setTimeout(function() {
                window.parent.location.reload();
              }, 2000);
            }
            
          }
      })

    })
    
  })
</script>
</body>
</html>
{:do_action('admin_js')}